<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
	<head>
		<script type="text/javascript" src="<?php echo base_url()?>js/jquery.js"></script>
		<script type="text/javascript" src="<?php echo base_url();?>js/jquery-ui.js"></script>
		<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/styles.css"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
		<script type="text/javascript">
function initialize(){
	var geocoder = new google.maps.Geocoder();
	var setLat = -7.8;
	var setLon = 110;   

	// argItems code taken from 
	// http://www.evolt.org/article/Javascript_to_Parse_URLs_in_the_Browser/17/14435/?format=print
	function argItems (theArgName) {
		sArgs = location.search.slice(1).split('&');
    		r = '';
    		for (var i = 0; i < sArgs.length; i++) {
        		if (sArgs[i].slice(0,sArgs[i].indexOf('=')) == theArgName) {
            			r = sArgs[i].slice(sArgs[i].indexOf('=')+1);
            			break;
        		}
    		}
    	return (r.length > 0 ? unescape(r).split(',') : '')
	}
	
	
	function getCoordForAddress(response) {
	
		if (!response || response.Status.code != 200) {
	        alert("Sorry, we were unable to geocode that address\n\n Sorry, dat adres bestaat blijkbaar niet!");
	    } else {
			place = response.Placemark[0];
			setLat = place.Point.coordinates[1];
			setLon = place.Point.coordinates[0];
			setLat = setLat.toFixed(6);
			setLon = setLon.toFixed(6);
			document.getElementById("frmLat").value = setLat;
			document.getElementById("frmLon").value = setLon;
		}
		placeMarker(setLat, setLon);
    }
	
	
	function placeMarker(setLat, setLon) {
		
		document.getElementById("frmLat").value = setLat;
		document.getElementById("frmLon").value = setLon;
	  
		var options = {
			zoom: 12,
			center: new google.maps.LatLng(setLat, setLon),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("map_canvas_add"), options);  
		var point = new google.maps.LatLng(setLat, setLon);
		var marker = new google.maps.Marker({
			position: point, 
			map: map
		});
		map.addOverlay(marker);

	}


	if (argItems("lat") == '' || argItems("lon") == '') {
		placeMarker(setLat, setLon);
    } else {
		var setLat = parseFloat( argItems("lat") );
		var setLon = parseFloat( argItems("lon") );
		setLat = setLat.toFixed(6);
	    setLon = setLon.toFixed(6);
		placeMarker(setLat, setLon);
    }	
}
    </script>
	<script type="text/javascript">
$(document).ready(function() {
	$("#selectcoord").click(function() {
		var lat =  $("#frmLat").val();	
		var lon =  $("#frmLon").val();	
		document.getElementById('latitude').value = $("#frmLat").val();	
		document.getElementById('longitude').value = $("#frmLon").val();	
	});
});
</script>
</head>
<body onload="initialize()">
	<div id="wrapper">
	<div id="wrapper3">
	<div id="onecolumn">

	<div id="kotakphoto8"><div class="titleprofile">Add Place From Coordinates</div><div class="backto"><?php echo anchor('place/add_map_place','Add place from address')?></div></div>
		<div id="map_canvas_add"></div>
		<div class="menuplace3">

		<form name="setLatLon" action="add_map_place_coord">
			<table>
				<tr><td>Latitude:</td><td><input type='text' name='lat' id="frmLat"></td></tr>
				<tr><td>Longitude:</td><td><input type='text' name='lon' id="frmLon"></td></tr>	
			</table>
			<input type="submit" name="setLatLon" value="Set Coordinates" id="setlatlon">
			<div id="selectcoord">Select</div>
		</form>
		<div class="clear"></div>
			
			<?php echo form_open_multipart('place/save2');?>
			<div class="label">Nama :</div><textarea name="name" class="content1"></textarea>
			<div class="label">Deskripsi :</div><textarea name="description" class="content2"></textarea>
			<div class="label">Alamat :</div><textarea id="address"  name="street"></textarea>
			<input id="latitude" type="hidden" name="latitude"/>
			<input id="longitude" type="hidden" name="longitude"/>
			<div class="label">Photo</div>
			<div id="divinputfile"> 
				<input name="userfile" type="file" size="30" id="userfile" onchange="this.form.fakefilepc.value = this.value;"/>
				<div id="fakeinputfile">
					<input name="fakefilepc" type="text" id="fakefilepc" />
				</div>
			</div>
			<div class="clear"></div>
			<div id="latar">
			<input type="submit" value="Create" class="savebutton">
			</div>
			</form>
        
	</div>
	
		<div id="tipsaddmap">
		Tips : Search alamat dengan mengetikkan nama alamat terdekat.
		</div>
		<?php echo $this->session->flashdata('error');  ?>
</div>
</div>
</div>
</body>
</html>